package com.bj.dz.service.impl;

import com.bj.dz.entity.GasDoorstationData;
import com.bj.dz.mapper.GasDoorstationDataMapper;
import com.bj.dz.service.GasDoorstationDataService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class GasDoorstationDataServiceImpl implements GasDoorstationDataService {

    @Resource
    private GasDoorstationDataMapper gasDoorstationDataMapper;

    public GasDoorstationData getGasDoorstationDataById(Integer id){
        return gasDoorstationDataMapper.getGasDoorstationDataById(id);
    }

    public List<GasDoorstationData>	getGasDoorstationDataListByMap(Map<String,Object> param){
        return gasDoorstationDataMapper.getGasDoorstationDataListByMap(param);
    }

    public Integer getGasDoorstationDataCountByMap(Map<String,Object> param){
        return gasDoorstationDataMapper.getGasDoorstationDataCountByMap(param);
    }

    @Transactional
    public boolean addGasDoorstationData(GasDoorstationData gasDoorstationData){
            return gasDoorstationDataMapper.insertGasDoorstationData(gasDoorstationData)>0?true:false;
    }

    @Transactional
    public boolean modifyGasDoorstationData(GasDoorstationData gasDoorstationData){
        return gasDoorstationDataMapper.updateGasDoorstationData(gasDoorstationData)>0?true:false;
    }

    @Transactional
    public boolean deleteGasDoorstationDataById(Integer id){
        return gasDoorstationDataMapper.deleteGasDoorstationDataById(id)>0?true:false;
    }

    public Page<GasDoorstationData> queryGasDoorstationDataPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = gasDoorstationDataMapper.getGasDoorstationDataCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<GasDoorstationData> gasDoorstationDataList = gasDoorstationDataMapper.getGasDoorstationDataListByMap(param);
        page.setRows(gasDoorstationDataList);
        return page;
    }

}
